<template>
  <div class="page-header-index-wide">
    <a-card :bordered="false"> 
      <a-tree
        :treeData="treeData"
      >
        <template slot="custom" slot-scope="item">
          <span>{{ item.title }}</span> 
 <span  type="primary"  class="but_type"  style="right:200px;" >

    <label 
            style="right:120px;"> <a-icon type="exclamation-circle-o;" /> 风险 4</label>   <a-divider type="vertical" style="height: 22px;  " />
        <label
            style="right:120px;"><a-icon  type="copy" />调查反馈 34/211</label>  <a-divider type="vertical" style="height: 22px;  " />
        <label
            style="right:120px;"><a-icon  type="book" />任务 1000/3421</label>  <a-divider type="vertical" style="height: 22px;  " />
        <label
            style="right:120px;"><a-icon  type="edit" />工作量 (人月)12039</label>  <a-divider type="vertical" style="height: 22px;  " />
 
 </span>

    

        </template>
      </a-tree>
    </a-card>
  </div>
</template>











<script>
const treeData = [
  {
    title: 'GCGH-000033 2024年信创转型工程',
    key: '0-0',
    scopedSlots: { title: 'custom' },
    children: [
      {
        title: 'GCGH-000033 2024年信创转型工程  一期规划',
        key: '0-0-0',
        scopedSlots: { title: 'custom' },
        children: [
          { title: '工程规划研讨会', key: '0-0-0-0', scopedSlots: { title: 'custom' } },
          { title: '工程规划工作说明书交付', key: '0-0-0-1', scopedSlots: { title: 'custom' } },
          { title: '工程执行与监督', key: '0-0-0-2', scopedSlots: { title: 'custom' } }
        ]
      },
      {
        title: 'GCGH-000033 2024年信创转型工程 二期规划',
        key: '0-0-1',
        scopedSlots: { title: 'custom' },
        children: [
          { title: '工程规划研讨会', key: '0-0-1-0', scopedSlots: { title: 'custom' } },
          { title: '工程规划工作说明书交付', key: '0-0-1-1', scopedSlots: { title: 'custom' } },
          { title: '工程执行与监督', key: '0-0-1-2', scopedSlots: { title: 'custom' } }
        ]
      },
      {
        title: 'GCGH-000033 2024年信创转型工程 三期规划',
        key: '0-0-2',
        scopedSlots: { title: 'custom' }
      }
    ]
  },
  {
    title: 'GCGH-000001 2023年信创转型工程',
    key: '0-1',
    scopedSlots: { title: 'custom' },
    children: [
      { title: 'GCGH-000001 2023年信创转型工程 一期规划', key: '0-1-0-0', scopedSlots: { title: 'custom' } },
      { title: 'GCGH-000001 2023年信创转型工程 二期规划', key: '0-1-0-1', scopedSlots: { title: 'custom' } },
      { title: 'GCGH-000001 2023年信创转型工程 三期规划', key: '0-1-0-2', scopedSlots: { title: 'custom' } }
    ]
  },
  {
    title: 'GCGH-000024 境外下主机',
    key: '工作规划研讨',
    scopedSlots: { title: 'custom' }
  }
]

export default {
  data () {
    return {
      treeData,
    }
  },
  methods: {
    // 递归查找
    searchOption (option, arr, type = 'delect') {
      console.log(option, arr)
      for (let s = 0; s < arr.length; s++) {
        console.log(arr[s].key, option.key)
        if (arr[s].key === option.key) {
          if (type === 'delect') {
            arr.splice(s, 1)
          } else {
          //这是模拟数据编辑数据
            this.$set(arr, s, {
              title: '12121212',
              key: '12121212',
              scopedSlots: { title: 'custom' }
            })
          }
          break
        } else if (arr[s].children && arr[s].children.length > 0) { // 递归条件
          this.searchOption(option, arr[s].children)
        } else {
          continue
        }
      }
    },
    append (data) {
    //模拟添加
      const newChild = { title: 'ceshi1',
        key: 'ceshi1',
        scopedSlots: { title: 'custom' },
        children: [] }
      if (!data.children) {
        this.$set(data, 'children', [])
      }
      data.children.push(newChild)
    },
    remove (data) { 
      this.searchOption(data, this.treeData)
    },
    edit (data) { 
      this.searchOption(data, this.treeData, 'edit')
    },
  }
}
</script>
<style lang="less" scoped>
.ant-tree-title {
  width: 100%;
}
.title {
  float: left;
}
.ant-card-body {
  :global {
    .ant-tree {
      line-height: 3;
      li {
        position: relative;
      }
    }
  }
}
.ant-card-body .but_type {
  float: right;
  position: absolute;
  right: 40px;
}
</style>

